<template>
  <div class="container">
    <div class="screen" ref="screenRef">
      <div class="top">
        <Top></Top>
      </div>
      <div class="bottom">
        <div class="left">
          <Tourist class="tourist" />
          <Sex class="sex" />
          <Age class="age" />
        </div>
        <div class="center">
          <Map class="map" />
          <Line class="line" />
        </div>
        <div class="right">
          <Rank class="rank" />
          <Year class="year" />
          <Statistic class="statistic" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="index">
import { onMounted, ref } from 'vue'
import Age from '@/views/screen/components/left/age.vue'
import Sex from '@/views/screen/components/left/sex.vue'
import Tourist from '@/views/screen/components/left/tourist.vue'
import Top from './components/top.vue'
import Map from '@/views/screen/components/center/map.vue'
import Line from '@/views/screen/components/center/line.vue'
import Rank from '@/views/screen/components/right/rank.vue'
import Year from '@/views/screen/components/right/year.vue'
import Statistic from '@/views/screen/components/right/statistic.vue'

//获取数据大屏展示内容的盒子DOM
const screenRef = ref()

onMounted(() => {
  //设置缩放比例
  screenRef.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
})

//定义大屏缩放比例
const getScale = (width = 1920, height = 1080) => {
  let scaleX = window.innerWidth / width
  let scaleY = window.innerHeight / height
  return Math.min(scaleX, scaleY)
}

//监听视口的变化
window.onresize = () => {
  screenRef.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
}
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url('./images/bg.png') no-repeat;
  background-size: cover;
  .screen {
    width: 1920px;
    height: 1080px;
    position: fixed;
    top: 50%;
    left: 50%;
    transform-origin: left top;

    .top {
      width: 100%;
      height: 40px;
    }
    .bottom {
      width: 100%;
      display: flex;
      height: 1040px;
      .right {
        flex: 1;
      }
      .left {
        flex: 1;
        display: flex;
        flex-direction: column;
        .tourist {
          flex: 1.2;
        }
        .sex {
          flex: 1;
        }
        .age {
          flex: 1;
        }
      }
      .center {
        flex: 2;
        height: 100%;
        display: flex;
        flex-direction: column;
        .map {
          flex: 3;
        }
        .line {
          flex: 1;
        }
      }
      .right {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-left: 20px;
        .rank {
          flex: 1.2;
        }
        .year {
          flex: 1;
        }
        .statistic {
          flex: 1;
        }
      }
    }
  }
}
</style>
